#include<reg51.h>
#include<lcd1602.h>
#define uchar unsigned char
#define uint unsigned int
uchar int_time;				//??????????
uchar second;
uchar minute;				//??????
uchar hour;				//??????
uchar code date[]="  H.I.T. CHINA  ";	//LCD?1??????
uchar code time[]=" TIME  23:59:55 ";	//LCD?2??????
uchar second=55,minute=59,hour=23;

void clock_init()
{
	uchar i,j;
	for(i=0;i<16;i++)
	{
		write_data(date[i]);
	}
write_com(0x80+0x40);
for(j=0;j<16;j++)
	{
		write_data(time[j]);
	}
}

void clock_write( uint s, uint m, uint h)
{
	write_sfm(0x47,h);
	write_sfm(0x4a,m);
	write_sfm(0x4d,s);
}

void main()
{
	init1602();		//LCD???
	clock_init();		//?????
TMOD=0x01;			 //?????T0???1??
EA=1;            			// ???? 
ET0=1; 				// ??T0?? 
TH0=(65536-46483)/256;	//?T0???
TL0=(65536-46483)%256;
TR0=1;
int_time=0;			//?????????????0
second=55;
minute=59;
hour=23;
while(1)
{
	clock_write(second ,minute, hour);
}
}
void  T0_interserve(void)  interrupt 1  using 1 	//T0???????
{	
	int_time++;				//?????1
 	if(int_time==20) 			//???????20?
 	{ 
		int_time=0; 			//???????0
 		second++;			//?????? 1
 	}
 	if(second==60)			//???60s
 	{ 
	second=0; 				//??????0
 	minute ++;				//?????? 1
 	}
	
if(minute==60)			//???60?
{ 	
	minute=0;		//??????0
	hour ++;		//???????1
}
if(hour==24)
{ 	
	hour=0;			//??????24,????????0
}
TH0=(65536-46083)/256;		//???T0????
TL0=(65536-46083)%256;
}
